package com.xy.ahoy

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.background
import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.gestures.awaitFirstDown
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawWithContent
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.layout.Layout
import androidx.compose.ui.layout.Measurable
import androidx.compose.ui.layout.MeasurePolicy
import androidx.compose.ui.layout.MeasureResult
import androidx.compose.ui.layout.MeasureScope
import androidx.compose.ui.layout.ParentDataModifier
import androidx.compose.ui.layout.layout
import androidx.compose.ui.modifier.modifierLocalConsumer
import androidx.compose.ui.modifier.modifierLocalOf
import androidx.compose.ui.modifier.modifierLocalProvider
import androidx.compose.ui.semantics.clearAndSetSemantics
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Constraints
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.dp
//import com.xy.ahoy.ui.theme.AhoyTheme

class TestActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContent {
//            GreetingPreview()
        }
    }
}

//@Composable
//fun Greeting(name: String, modifier: Modifier = Modifier) {
//    Text(
//        text = "Hello $name!",
//        modifier = modifier
//    )
//}
//
//@Preview(showBackground = true)
//@Composable
//fun GreetingPreview() {
//    AhoyTheme {
//        Text("1111111", Modifier.layout { measurable, constraints ->
//            val placeable = measurable.measure(constraints)
//            layout(placeable.width,placeable.height){
//                placeable.placeRelative(0,0)
//            }
//        }.drawWithContent{
//            drawCircle(Color.Red)
//            drawContent()
//        })
//    }
//}
//
//@Preview
//@Composable
//fun testClick(){
//
//    Box(Modifier.padding(20.dp).background(Color.Gray).size(40.dp).combinedClickable(onLongClick = {
//
//    }, onDoubleClick = {
//
//    }, onClick = {
//
//    })){
//
//    }
//
//}
//
//@Preview
//@Composable
//fun testClick1(){
//
//    Box(Modifier.padding(20.dp).background(Color.Green).size(40.dp).pointerInput(Unit){
////        detectTapGestures(onTap = {}, onDoubleTap = {}, onPress = {}, onLongPress = {})
////        detectDragGestures(onDragStart = {
////
////        },onDragEnd = {
////
////        },onDragCancel = {
////
////        },onDrag = {change: PointerInputChange, dragAmount: Offset ->
////
////        })
//        awaitPointerEventScope {
//            val down = awaitFirstDown()
//        }
//
//
//    }){
//
//    }
//
//}
//
//@Composable
//fun CustomLayout(modifier: Modifier = Modifier,content:@Composable () -> Unit){
//    Layout(content,modifier,object : MeasurePolicy{
//        override fun MeasureScope.measure(
//            measurables: List<Measurable>,
//            constraints: Constraints
//        ): MeasureResult {
//            measurables.forEach {
//                //拿到子组件的数据
//                val data = it.parentData as? Layout2Data
//
//            }
//
//            return layout(100, 100, placementBlock = {
//
//            })
//        }
//    })
//}
//
//class Layout2Data(var weight: Float = 0f,var big: Boolean = false)
//
//fun Modifier.bigData(big: Boolean) = then(object : ParentDataModifier{
//    override fun Density.modifyParentData(parentData: Any?): Any? {
//        //数据融合，之前设置的被覆盖
//        return ((parentData as? Layout2Data) ?: Layout2Data()).also { it.big = big }
//    }
//})
//
//fun Modifier.weightData(weight: Float) = then(object : ParentDataModifier{
//    override fun Density.modifyParentData(parentData: Any?): Any? {
//        //数据融合，之前设置的被覆盖
//        return ((parentData as? Layout2Data) ?: Layout2Data()).also { it.weight = weight}
//    }
//})
//
//
//@Preview
//@Composable
//fun testClick2(){
//    CustomLayout(Modifier.size(200.dp)) {
//        Text("", Modifier.bigData(true).clearAndSetSemantics(){})
//        Text("", Modifier.bigData(false))
//        Text("", Modifier.bigData(false))
//    }
//}
//
//
//@Preview
//@Composable
//fun testClick3(){
//    val sharedKey =  modifierLocalOf { "" }
//    CustomLayout(Modifier.size(200.dp).modifierLocalProvider(sharedKey){
//        ""
//    }) {
//        Text("", Modifier.modifierLocalConsumer{
//            sharedKey
//        })
//    }
//}